package com.itbaizhan.cxpt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itbaizhan.cxpt.entity.CxptBz;
import com.itbaizhan.cxpt.mapper.CxptBzMapper;
import com.itbaizhan.cxpt.service.CxptBzService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class CxptBzServiceImpl extends ServiceImpl<CxptBzMapper, CxptBz> implements CxptBzService {

    @Override
    public IPage<CxptBz> pageQuery(Integer page, Integer size, String keyword) {
        Page<CxptBz> pageParam = new Page<>(page, size);
        LambdaQueryWrapper<CxptBz> wrapper = new LambdaQueryWrapper<>();
        
        if (StringUtils.hasText(keyword)) {
            wrapper.like(CxptBz::getA100, keyword)
                   .or()
                   .like(CxptBz::getA298, keyword);
        }
        
        return this.page(pageParam, wrapper);
    }

    @Override
    public CxptBz getByStandardNo(String standardNo) {
        if (!StringUtils.hasText(standardNo)) {
            return null;
        }
        
        LambdaQueryWrapper<CxptBz> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CxptBz::getA100, standardNo);
        return this.getOne(wrapper);
    }

    @Override
    public List<CxptBz> queryByPublishDateRange(String startDate, String endDate) {
        LambdaQueryWrapper<CxptBz> wrapper = new LambdaQueryWrapper<>();
        if (StringUtils.hasText(startDate)) {
            wrapper.ge(CxptBz::getA101, startDate);
        }
        if (StringUtils.hasText(endDate)) {
            wrapper.le(CxptBz::getA101, endDate);
        }
        return this.list(wrapper);
    }
}